<template>
	<!-- 部门编辑 -->
	<div>
		<div class="edit-top">
			编辑信息
			<i class="el-icon-close" @click='cancel'></i>
		</div>
		<div class="edit-content">
			<div class="edit-title">部门信息</div>
			<div class="edit-item">
				<label>部门编码</label><input v-model="info.deptCode" readonly="readonly" type="text" />
			</div>
			<div class="edit-item">
				<label>部门名称</label><input v-model="info.deptName" type="text" />
			</div>
			<div class="edit-item">
				<label>所属部门</label><select v-model="info.parentId">
				<option value="0"></option>
				<option v-for="item in dep_list" :value="item.id" >{{item.deptName}}</option>
				</select>
			</div>
			<div class="edit-item">
				<label>部门类别</label><select v-model="info.type">
				<option value="0" selected="selected">一般部门</option>
				<option value="1" >换电站</option>
				<option value="3" >外部部门</option>
				</select>
			</div>
			<div class="edit-item">
				<label>排序</label><input type="number" v-model="info.orderNum" />
			</div>

		</div>
		<div class="edit-bottom">
			<span @click='cancel'>取消</span>
			<el-button @click='save' type="primary">保存</el-button>
		</div>
	</div>
</template>

<script>
	let _this;
	export default {
		props:['id'],
		data() {
			return {
				dep_list:[],
				info: {
					deptName: '',
					deptCode: '',
					parentId: 0,
					type:0,
					orderNum:''
					
				}
			}
		},
		created() {
			_this = this;
		},
		mounted() {
			this.get_info();
			this.get_dep_list();
		},
		methods: {
			get_info(){
				this.$axios.get(this.$global.serverIp + 'admin/sysDept/detail/'+this.id)
					.then(function(res) {
						if (res != '')
							_this.info = res.data;
					})
				
			},
			get_dep_list(){
				this.$axios.post(this.$global.serverIp + 'admin/sysDept/findPage', {
						"limit": "10000",
						"page": "1"
					})
					.then(function(res) {
						if (res != '') {
							_this.dep_list = res.data.list;
						}
					})
			},
			save() {
				if (this.info.deptName == "") {
					this.$popup.open('部门名称不能为空');
					return;
				}
				this.$axios.post(this.$global.serverIp + 'admin/sysDept/save', _this.info)
					.then(function(res) {
						if (res != '') {
							_this.success('编辑成功');
						}
					})
			
			},
			success(content) {
				this.$alert(content, '提示', {
					confirmButtonText: '确定',
					callback: action => {
						_this.$emit("saveEdit", 2);
					}
				});
			},
			
			cancel() {
				this.$emit("saveEdit", 1);
			}
		}
	}
	import '@/assets/css/edit.css'
</script>
